import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
} from '@nestjs/common';
import { CategoryService } from './category.service';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import {
  CreateCategoryDto,
  UpdateCategoryDto,
  SortCategoryDto,
  QueryCategoryDto,
} from './category.dto';

@Controller('categories')
@ApiTags('Product-分类管理')
export class CategoryController {
  constructor(private readonly categoryService: CategoryService) {}

  @Post('create')
  @ApiOperation({ summary: '创建产品分类' })
  create(@Body() dto: CreateCategoryDto) {
    return this.categoryService.create(dto);
  }

  @Get('list')
  @ApiOperation({ summary: '查询所有产品分类' })
  findAll(@Query() dto: QueryCategoryDto) {
    return this.categoryService.findAll(dto);
  }

  @Get('getInfoById')
  @ApiOperation({ summary: '查询单个产品分类' })
  findOne(@Query('id') id: string) {
    return this.categoryService.findOne(id);
  }

  @Post('updateInfoById')
  @ApiOperation({ summary: '更新产品分类' })
  update(@Query('id') id: string, @Body() dto: UpdateCategoryDto) {
    return this.categoryService.update(id, dto);
  }

  @Get('delete')
  @ApiOperation({ summary: '删除产品分类' })
  remove(@Query('id') id: string) {
    return this.categoryService.remove(id);
  }

  @Post('sort')
  @ApiOperation({ summary: '批量更新分类排序' })
  sortCategories(@Body() dto: SortCategoryDto) {
    return this.categoryService.sortCategories(dto);
  }
}
